package com.fxb.doraemon.human.service;

import com.fxb.doraemon.human.entity.User;
import com.fxb.doraemon.human.mapper.UserMapper;
import com.fxb.doraemon.human.vo.UserQueryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 用户Service
 *
 * @author fangjiaxiaobai@gmail.com
 * @since 2019-05-07
 */
@Service
@Transactional
@Slf4j
public class UserService {


    private UserMapper userMapper;

    /**
     * 根据id获取用户
     *
     * @param id 用户的id
     * @return 用户信息
     */
    public User get(String id) {
        return userMapper.select(id);
    }

    /**
     * 保存用户
     *
     * @param user 带保存的用户数据
     * @return 保存后的主键
     */
    public Integer saveUser(User user) {
        Integer insert = this.userMapper.insert(user);
        log.debug("[saveUser - 保存用户] 成功保存{}条用户信息,生成的用户Id为:{}", insert, user.getId());
        return user.getId();
    }

    public Integer deleteUser(String id) {
        return this.userMapper.delete(id);
    }

    public Integer updateUserById(User user) {
        return this.userMapper.update(user);
    }

    /**
     * 获取用户列表
     *
     * @param user 查询的条件
     * @return 查询的列表
     */
    public List<UserQueryVo> getUserFully(User user) {
        return this.userMapper.selectUserFully(user);
    }

    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

}
